import { Line3, Vector3 } from 'three';

export enum EFix {
  start,
  end,
}

export function changeLine({
  line,
  size,
  fix,
}: {
  line: Line3;
  size: number;
  fix?: EFix;
}) {
  const direction = line.delta(new Vector3()).normalize();
  const changeDirection =
    fix === EFix.start ? direction.clone().negate() : direction;
  const changePoint = fix === EFix.start ? 'start' : 'end';
  const fixPoint = fix === EFix.start ? 'end' : 'start';
  line[changePoint] = line[fixPoint]
    .clone()
    .addScaledVector(changeDirection, size);
  return line;
}

export function moveLine({
  line,
  direction,
  delta,
}: {
  line: Line3;
  direction: Vector3;
  delta: number;
}) {
  line.start.addScaledVector(direction, delta);
  line.end.addScaledVector(direction, delta);
  return line;
}
